//
//  NineteenViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/4/2.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class NineteenViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white;
        self.onCreatUIForNivation();
        // Do any additional setup after loading the view.
        
        let spinner = JHSpinnerView.showOnView(view, spinnerColor:UIColor.red, overlay:.roundedSquare, overlayColor:UIColor.black.withAlphaComponent(0.6), fullCycleTime:2.55, text:nil)

        delay(36) { () -> () in
          spinner.dismiss()
        }
        
//        showSampleDeterminiteSpinner()
    }
    
    fileprivate func onCreatUIForNivation() {
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", style: .done, target: self, action: #selector(onBackAction));
    }
    
    func showSampleDeterminiteSpinner() {
       let spinner = JHSpinnerView.showDeterminiteSpinnerOnView(view, spinnerColor: .white, backgroundColor: .black, fullCycleTime: 2.55, initialProgress: 0.0)
       
       delay(1) { () -> () in
         spinner.progress = 0.1
       }
       delay(2) { () -> () in
         spinner.progress = 0.3
       }
       delay(3) { () -> () in
         spinner.progress = 0.5
       }
       delay(4) { () -> () in
         spinner.progress = 0.7
       }
       delay(5) { () -> () in
         spinner.progress = 0.9
       }
       
       
       delay(6) { () -> () in
         spinner.dismiss()
       }
       
     }
     
   func delay(_ delay:Double, closure:@escaping ()->()) {
       DispatchQueue.main.asyncAfter(
           deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: closure)
   }

    
    //TODO:Actions
    @objc fileprivate func onBackAction() {
        self.navigationController?.dismiss(animated: true, completion: nil);
    }
}
